<template><div><!-- `more` 注释之前的内容被视为文章摘要。 -->
<!-- more -->
<h2 id="go-安装" tabindex="-1"><a class="header-anchor" href="#go-安装" aria-hidden="true">#</a> Go 安装</h2>
<p>Go安装前面已经做了介绍，请参考：Go-在windows11系统安装配置</p>
<h2 id="go-配置" tabindex="-1"><a class="header-anchor" href="#go-配置" aria-hidden="true">#</a> Go 配置</h2>
<h3 id="go-module" tabindex="-1"><a class="header-anchor" href="#go-module" aria-hidden="true">#</a> go module</h3>
<p>go管理依赖工具
需要开启
命令行输入：</p>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>go env -w GO111MODULE="on"
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="修改go代理地址" tabindex="-1"><a class="header-anchor" href="#修改go代理地址" aria-hidden="true">#</a> 修改go代理地址</h3>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>go env -w GOPROXY=https://goproxy.cn
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="查看env文件可以使用" tabindex="-1"><a class="header-anchor" href="#查看env文件可以使用" aria-hidden="true">#</a> 查看env文件可以使用</h3>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>go env
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="goctl-安装" tabindex="-1"><a class="header-anchor" href="#goctl-安装" aria-hidden="true">#</a> Goctl 安装</h3>
<p>goctl 是 go-zero 微服务框架下的代码生成工具</p>
<p>安装命令：</p>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>go install github.com/zeromicro/go-zero/tools/goctl@latest
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><blockquote>
<p>注意：由于版本问题，go get 需要改成 go install</p>
</blockquote>
<p>通过此命令，可以将 goctl 工具安装到 <code v-pre>%GOPATH%/bin</code> 目录下。</p>
<p><code v-pre>%GOPATH%</code> 如何配置，请参考：</p>
<p>Go-在windows11系统安装配置</p>
<p><a href="https://blog.csdn.net/mokyzone/article/details/124323805?spm=1001.2014.3001.5502" target="_blank" rel="noopener noreferrer">https://blog.csdn.net/mokyzone/article/details/124323805?spm=1001.2014.3001.5502<ExternalLinkIcon/></a></p>
<p>验证是否成功，执行</p>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>goctl -v
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>显示版本，即代表安装成功</p>
<h2 id="protoc-安装" tabindex="-1"><a class="header-anchor" href="#protoc-安装" aria-hidden="true">#</a> Protoc 安装</h2>
<p>打开 protobuf</p>
<p><a href="https://github.com/protocolbuffers/protobuf/releases" target="_blank" rel="noopener noreferrer">https://github.com/protocolbuffers/protobuf/releases<ExternalLinkIcon/></a></p>
<p>选择适合自己win系统的压缩包文件，下载压缩包</p>
<p>解压文件，把解压
找到目录文件：bin\protoc.exe</p>
<p>把
protoc.exe
拷贝到
%GOPATH%/bin
目录即可
检查是否安装好，输入：</p>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>protoc --version
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p><img src="@source/编程文档/go-zero/img/2022_06_13_23_11_55.png" alt="" loading="lazy"></p>
<p>至此，windows11下配置go-zero环境已经完成。</p>
<h2 id="测试项目" tabindex="-1"><a class="header-anchor" href="#测试项目" aria-hidden="true">#</a> 测试项目</h2>
<h4 id="下载" tabindex="-1"><a class="header-anchor" href="#下载" aria-hidden="true">#</a> 下载</h4>
<p><a href="https://github.com/zeromicro/go-zero-demo" target="_blank" rel="noopener noreferrer">https://github.com/zeromicro/go-zero-demo<ExternalLinkIcon/></a></p>
<h4 id="在-go-zero-demo-目录下" tabindex="-1"><a class="header-anchor" href="#在-go-zero-demo-目录下" aria-hidden="true">#</a> 在 go-zero-demo 目录下</h4>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>go mod tidy
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h4 id="启动etcd" tabindex="-1"><a class="header-anchor" href="#启动etcd" aria-hidden="true">#</a> 启动etcd</h4>
<p>下载</p>
<p><a href="https://github.com/etcd-io/etcd/releases" target="_blank" rel="noopener noreferrer">https://github.com/etcd-io/etcd/releases<ExternalLinkIcon/></a></p>
<p>双击etcd.exe运行etcd服务</p>
<h4 id="启动user-rpc" tabindex="-1"><a class="header-anchor" href="#启动user-rpc" aria-hidden="true">#</a> 启动user rpc</h4>
<p>在 mall/user/rpc 目录</p>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>go run user.go -f etc/user.yaml
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Starting rpc server at 127.0.0.1:8080...</p>
<h4 id="启动order-api" tabindex="-1"><a class="header-anchor" href="#启动order-api" aria-hidden="true">#</a> 启动order api</h4>
<p>在 mall/order/api 目录</p>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>go run order.go -f etc/order.yaml
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><p>Starting server at 0.0.0.0:8888...</p>
<h4 id="访问order-api" tabindex="-1"><a class="header-anchor" href="#访问order-api" aria-hidden="true">#</a> 访问order api</h4>
<p><a href="http://localhost:8888/api/order/get/1" target="_blank" rel="noopener noreferrer">http://localhost:8888/api/order/get/1<ExternalLinkIcon/></a></p>
<p><img src="@source/编程文档/go-zero/img/2022_06_13_23_53_11.png" alt="" loading="lazy"></p>
<h2 id="vscode高亮插件" tabindex="-1"><a class="header-anchor" href="#vscode高亮插件" aria-hidden="true">#</a> vscode高亮插件</h2>
<div class="language-text ext-text line-numbers-mode"><pre v-pre class="language-text"><code>goctl
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h2 id="官方文档" tabindex="-1"><a class="header-anchor" href="#官方文档" aria-hidden="true">#</a> 官方文档</h2>
<p><a href="https://legacy.go-zero.dev/cn/concept-introduction.html" target="_blank" rel="noopener noreferrer">https://legacy.go-zero.dev/cn/concept-introduction.html<ExternalLinkIcon/></a></p>
</div></template>
